<script>
  function fib(n, cur = 0, next = 1) {
    if (n == 0) return 0;
    if (n == 1) return next;
    return fib(n - 1, next, cur + next);
  }
  console.log(fib(5)); //sy-log


  // 创建一个空对象,作为缓存的容器
  /* let cache = {};
  let count = 0;

  function fib(n) {
    count++;
    if (n === 1 || n === 2) {
      return 1;
    }
    if (cache[n]) {
      return cache[n];
    }
    let ret = fib(n - 1) + fib(n - 2);
    return cache[n] = ret;
  } */
</script>